const Storage = window.localStorage;

export const getStorage = (keyName) => {
  const resStr = Storage.getItem(keyName) ?? '';
  if (resStr) {
    try {
      return JSON.parse(resStr)
    } catch (e) {
      return resStr
    }
  } else {
    return resStr
  }
}

export const setStorage = (keyName, data) => {
  if (data === undefined || data === null) {
    removeStorage(keyName)
  } else {
    Storage.setItem(keyName, JSON.stringify(data));
  }
}

export const removeStorage = (keyName) => {
  Storage.removeItem(keyName);
}